import React, {Component} from 'react';

import "../../styles/homelist.css"
import {withRouter} from 'react-router-dom'
import {index_goodlist} from '../../api'
class HomeList extends Component{
    constructor(props){
        super(props);
        this.state={
            list : [
            ],
            currrentIndex:0
        }
    }
    componentDidMount(){
        index_goodlist().then((res)=>{
            console.log("推荐",res.data)
            this.setState({
                list:res.data.list,
            })
        })
    }
    handleClick(id){
        console.log(id)
        this.props.history.push(`/detail/${id}`)
    }
    render(){
        return(
            <div className='homelist'>
                <div className='li'>
                  
                {
                        this.state.list.map((item,index)=>{
                            return (
                                <div className='box2' onClick={()=>{
                                    this.handleClick(item.id)
                                }} key={item.id}>
                                <img src={item.pic} alt="" />
                            <p>{item.name}</p>
                            <span className='p1'>原价:￥{item.salesPrice.value}</span>
                            {/* <span className='p2'>抢购价:￥<i>{item.salesPrice.value}</i></span> */}
                            </div>
                            )
                        })
                    }
                </div>
            </div>
        )
    }
}

export default withRouter(HomeList);